package main

import (
	"fmt"
	"runtime"
	"time"
)

func Bf(ch chan int, process int) chan int {
	runtime.GOMAXPROCS(runtime.NumCPU())
	rs := make(chan int)

	for i := 0; i < process; i++ {
		go func() {
			for item := range ch {
				fmt.Println(item)
				time.Sleep(2 * time.Second)
			}
			rs <- 0
			fmt.Println("ok")
		}()
	}
	return rs
}
func Process(pages []int, nubpro int) {
	ch := make(chan int, runtime.NumCPU())
	rs := Bf(ch, nubpro)

	for i := 0; i < len(pages); i++ {
		ch <- pages[i]
	}
	close(ch)

	for i := 0; i < nubpro; i++ {
		<-rs
		fmt.Println("get")
	}
}
func main() {
	fmt.Println("starting......")
	pages := []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
	Process(pages, 3)
}
